import {getStorageSources, WORKSTATE, workSwitch} from "./public/CreepPublicAction.js";

/**
 * 升级者工作逻辑
 * @param {Creep} creep
 * @param sourcesIndex
 */
export const tempUpgraderRun = (creep,sourcesIndex) => {
    //工作逻辑转换
    workSwitch(creep, RESOURCE_ENERGY)
    if (creep.memory[WORKSTATE]) {
        workCore(creep)
    } else {
        getSources(creep,sourcesIndex)
    }

};

const workCore = (creep) => {
    if (creep.upgradeController(creep.room.controller) === ERR_NOT_IN_RANGE) {
        creep.moveTo(creep.room.controller, {visualizePathStyle: {stroke: '#aeef06'}});
    }
}

const getSources = (creep,sourcesIndex) => {
    const storage = creep.room.storage
    if (storage.store.getFreeCapacity(RESOURCE_ENERGY) < storage.store.getCapacity() ) {
        getStorageSources(creep, sourcesIndex,'#aeef06')
    }

}
